package main.java.com.fronted.css;

import javax.swing.*;
import java.awt.*;

public class flight_control {
    public void frame_create(){
        JFrame frame1 = new JFrame("Meta_cosmic");
        frame1.setLayout(null);
        frame1.setResizable(false);
        frame1.getContentPane().setBackground(Color.cyan);

        //添加参数内容与实验室选择
        JLabel l0 = new JLabel("<html>Choose your desired Lab </html>");
        l0.setForeground(Color.black);
        l0.setFont(new Font("Times New Roman", Font.BOLD, 25));
        l0.setBounds(170,0,1000,35);
        frame1.add(l0);

        //添加图片与实验按钮触发器：特定选为文字
        //图片形状压缩为指定大小
        /*
        try{
            File inputFile = new File("src/main/resources/lab1.png");
            BufferedImage inputImage = ImageIO.read(inputFile);
            int compressedWidth = 200;
            int compressedHeight = 200;
            BufferedImage outputImage = new BufferedImage(compressedWidth, compressedHeight, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics2D = outputImage.createGraphics();
            graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graphics2D.drawImage(inputImage, 0, 0, compressedWidth, compressedHeight, null);
            graphics2D.dispose();
            File outputFile = new File("src/main/resources/lab1.png");
            ImageIO.write(outputImage, "png", outputFile);
        }catch(IOException e){
            e.printStackTrace();
        }
        try{
            File inputFile = new File("src/main/resources/lab2.png");
            BufferedImage inputImage = ImageIO.read(inputFile);
            int compressedWidth = 200;
            int compressedHeight = 200;
            BufferedImage outputImage = new BufferedImage(compressedWidth, compressedHeight, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics2D = outputImage.createGraphics();
            graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graphics2D.drawImage(inputImage, 0, 0, compressedWidth, compressedHeight, null);
            graphics2D.dispose();
            File outputFile = new File("src/main/resources/lab2.png");
            ImageIO.write(outputImage, "png", outputFile);
        }catch(IOException e){
            e.printStackTrace();
        }
        try{
            File inputFile = new File("src/main/resources/lab3.png");
            BufferedImage inputImage = ImageIO.read(inputFile);
            int compressedWidth = 200;
            int compressedHeight = 200;
            BufferedImage outputImage = new BufferedImage(compressedWidth, compressedHeight, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics2D = outputImage.createGraphics();
            graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graphics2D.drawImage(inputImage, 0, 0, compressedWidth, compressedHeight, null);
            graphics2D.dispose();
            File outputFile = new File("src/main/resources/lab3.png");
            ImageIO.write(outputImage, "png", outputFile);
        }catch(IOException e){
            e.printStackTrace();
        }


        try{
            File inputFile = new File("src/main/resources/lab4.png");
            BufferedImage inputImage = ImageIO.read(inputFile);
            int compressedWidth = 200;
            int compressedHeight = 200;
            BufferedImage outputImage = new BufferedImage(compressedWidth, compressedHeight, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics2D = outputImage.createGraphics();
            graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graphics2D.drawImage(inputImage, 0, 0, compressedWidth, compressedHeight, null);
            graphics2D.dispose();
            File outputFile = new File("src/main/resources/lab4.png");
            ImageIO.write(outputImage, "png", outputFile);
        }catch(IOException e){
            e.printStackTrace();
        }
        */

        JLabel l1 = new JLabel();
        ImageIcon imageIcon1 = new ImageIcon("src/main/resources/lab1.png");
        l1.setIcon(imageIcon1);
        l1.setBounds(80, 20, imageIcon1.getIconWidth(), imageIcon1.getIconHeight());
        frame1.add(l1);

        JLabel l2 = new JLabel();
        ImageIcon imageIcon2 = new ImageIcon("src/main/resources/lab2.png");
        l2.setIcon(imageIcon2);
        l2.setBounds(380, 20, imageIcon1.getIconWidth(), imageIcon1.getIconHeight());
        frame1.add(l2);

        JLabel l3 = new JLabel();
        ImageIcon imageIcon3 = new ImageIcon("src/main/resources/lab4.png");
        l3.setIcon(imageIcon3);
        l3.setBounds(80, 260, imageIcon1.getIconWidth(), imageIcon1.getIconHeight());
        frame1.add(l3);

        JLabel l4 = new JLabel();
        ImageIcon imageIcon4 = new ImageIcon("src/main/resources/lab4.png");
        l4.setIcon(imageIcon4);
        l4.setBounds(380, 260, imageIcon1.getIconWidth(), imageIcon1.getIconHeight());
        frame1.add(l4);

        //添加按钮
        JButton j1 = new JButton("三线摆测转动惯量");
        j1.setBounds(80,240,200,20);
        j1.setLayout(null);
        j1.setUI(new New_botton.RoundedButtonUI());
        frame1.add(j1);

        JButton j2 =new JButton("对称法测电阻");
        j2.setBounds(380,240,200,20);
        j2.setUI(new New_botton.RoundedButtonUI());
        j2.setLayout(null);
        frame1.add(j2);

        JButton j3 = new JButton("测太空的重力加速度");
        j3.setBounds(80,480 ,200,20);
        j3.setUI(new New_botton.RoundedButtonUI());
        j3.setLayout(null);
        frame1.add(j3);

        JButton j4 =new JButton("对称法测透镜焦距");
        j4.setLayout(null);
        j4.setBounds(380,480,200,20);
        j4.setUI(new New_botton.RoundedButtonUI());
        frame1.add(j4);


        frame1.setVisible(true);
        frame1.setSize(800, 570);
        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new flight_control().frame_create();
    }
}
